package com.ks.BusAlarm;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;

public class SearchView extends Activity {

	Button btnSearch;
	Button btnStop;
	EditText editBusStopNum;
	EditText editBusNum;
	Intent service;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.searchview);

		editBusStopNum = (EditText) findViewById(R.id.editBusStopNum);
		editBusNum = (EditText) findViewById(R.id.editBusNum);

		service = new Intent(getApplicationContext(), MyService.class);

		btnSearch = (Button) findViewById(R.id.btn_search);

		btnSearch.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				service.putExtra("BusStopNum", editBusStopNum.getText()
						.toString());
				service.putExtra("BusNum", editBusNum.getText().toString());

				startService(service);

			}
		});

		btnStop = (Button) findViewById(R.id.btn_stop);
		btnStop.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				Intent ServiceDestroyer = new Intent(getApplicationContext(),
						MyService.class);
				stopService(ServiceDestroyer);

			}
		});

		Spinner s = (Spinner) findViewById(R.id.spinner);
		ArrayAdapter adapter = ArrayAdapter.createFromResource(this,
				R.array.stops, android.R.layout.simple_spinner_item);
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		s.setAdapter(adapter);

		s.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {

				editBusStopNum.setText(String.valueOf(arg0
						.getItemAtPosition(arg2)));

			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});
	}

}
